home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16366 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.informatik.uni-kiel.de!ma
  2. From: ma@informatik.uni-kiel.de (Martin Ameskamp)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Determining Array size
  5. Date: 10 Apr 1996 15:44:02 GMT
  6. Organization: Dept. of Computer Science, University of Kiel, FRG
  7. Message-ID: <4kgl02$gnn@gutemine.informatik.uni-kiel.de>
  8. References: <316a9cef.44425478@news.synapse.net>
  9. NNTP-Posting-Host: rigel.informatik.uni-kiel.de
  10.  
  11. In <316a9cef.44425478@news.synapse.net> phill@synapse.net (Phil Lachance) writes:
  12.  
  13. >I would like to send an array to a function having to send the array
  14. >size, is there any way to determine the size of an array?  
  15.  
  16.     If we're talking about low-level, C-type arrays - no.
  17.     The only way to get information about the array size is to call
  18.     sizeof on the actual array variable (_NOT_ on a pointer that
  19.     points to the first element of the array).
  20.  
  21.     A function that is passed an array as a parameter doesn't know
  22.     the size (of course, you can explicitly pass the size in a separate
  23.     parameter or use a special element - like 0 in C strings - to
  24.     denote the array end or ...)
  25.  
  26.     Since this is c.l.c++, your best bet is probably to use one of the
  27.     many array classes floating around. Most of these provide a method
  28.     to find out the size of the array.
  29.  
  30.     Martin
  31.